package base.io;

import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

// 按照 一个一个 字符进行读取
public class ReaderAndWriterTest001 {
  
  public static final String COMMON_PATH = "E:%stest%s";
  
  public static void main(String[] args) throws IOException {
    String filePath = String.format(COMMON_PATH + "1.input.md", File.separator, File.separator);
    String outputPath = String.format(COMMON_PATH + "1.output.md", File.separator, File.separator);
    
    File file = new File(filePath);
    File outFile = new File(outputPath);
    if (!outFile.exists())
      outFile.createNewFile();
    
    FileReader fileReader = new FileReader(file);
    // 如果添加第二个参数后 表示是追加模式
    FileWriter fileWriter = new FileWriter(outFile, true);
    int len;
    while ((len = fileReader.read()) != -1) {
      System.out.println((char) len);
      fileWriter.write((char) len);
    }
    
    fileReader.close();
    fileWriter.close();
  }
}
